// 暂无作用，未来研究函数复用时用

function getAuthCode () {
  // 验证手机号
  if (!checkBindAccount()) {
    return false
  } else {
    const TIME_COUNT = 60 // 更改倒计时时间
    if (!this.timer) {
      this.count = TIME_COUNT
      this.show = false
      this.timer = setInterval(() => {
        if (this.count > 0 && this.count <= TIME_COUNT) {
          this.count--
        } else {
          this.show = true
          clearInterval(this.timer) // 清除定时器
          this.timer = null
        }
      }, 1000)
    }
  }
}

function checkBindAccount () {
  if (this.form.bindType === 'phoneNumber') {
    const phone = this.form.bindAccount
    if (!/^1[3456789]\d{9}$/.test(phone)) {
      this.$message.error('请填写正确的手机号')
      return false
    } else {
      return true
    }
  } else if (this.form.bindType === 'email') {
    const email = this.form.bindAccount
    if (!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email)) {
      this.$message.error('请填写正确的电子邮箱')
      return false
    } else {
      return true
    }
  }
}

function clearBindAccountInput () {
  this.form.bindAccount = ''
}
export default {
  getAuthCode,
  clearBindAccountInput
}
